#include <iostream>
using namespace std;
//并查集

const int N = 2e5 + 10;
int arr[N];

int find(int pos)
{
    if(arr[pos] == pos) return pos;
    return arr[pos] = find(arr[pos]);
}

void un(int a, int b)
{
    int a1 = find(a);
    int b1 = find(b);
    arr[a1] = b1;
}

void check(int a, int b)
{
    int a1 = find(a);
    int b1 = find(b);
    if(a1 == b1) cout << "Y" << endl;
    else cout << "N" << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    int n,m; cin >> n >> m;
    //初始化
    for(int i = 1; i < N; i++)
        {
            arr[i] = i;
        }
    for(int i = 1; i <= m; i++)
        {
            int z,a,b; cin >> z >> a >> b;
            if(z == 1) 
            {
                un(a,b);
            }
            else 
            {
                check(a,b);
            }
        }
    
    return 0;
}